<?php


namespace app\api\controller\v1;


use app\common\controller\UserBaseController;
use app\common\library\AlimpModel;
use app\common\library\IDMan;

class AlirelationController extends UserBaseController
{
    //绑定用户
    function BindAction()
    {
        //hilog::set_pfx('ali');

        $this->paramlist=[
            'token' => 'string',
        ];

        $this->check_params();
        $this->check_token();


        $id  = IDMan::order_id();
        $ret = (new AlimpModel())->bind($id,'2088831946871474','贺州舢舨网络科技有限公司');

        $this->resp['info'] = $ret;
    }

    //解绑
    function UnBindAction()
    {
        //hilog::set_pfx('ali');

        $this->paramlist=[
            'token' => 'string',
        ];

        $this->check_params();
        $this->check_token();


        $id  = IDMan::order_id();
        $ret = (new AlimpModel())->unbind($id,'2088831940789245','铜陵舢舨网络科技有限公司');

        $this->resp['info'] = $ret;
    }

    //查询
    function RelationQueryAction()
    {
        //hilog::set_pfx('ali');

        $this->paramlist=[
            'token' => 'string',
        ];

        $this->check_params();
        $this->check_token();


        $id  = IDMan::order_id();
        $ret = (new AlimpModel())->query($id);

        $this->resp['info'] = $ret;
    }

    //测试分账
    function settleAction()
    {
       // hilog::set_pfx('ali');

        $this->paramlist=[
            'token' => 'string',
            'ali_id'=> 'string',
            'amount' => 'int',
        ];

        $this->check_params();
        $this->check_token();

        $order_id  = IDMan::order_id();
        $receivers =[
            ['account'=>'2088831940789245',
             'amount' =>$this->argv['amount'],
             'desc' =>'铜陵分账'
            ],
        ];
        $ret = (new AlimpModel())->create_settle_request($order_id,$this->argv['ali_id'],$receivers);

        $this->resp['info'] = $ret;
    }

    //测试分账退款
    function settle_refundAction()
    {
        //hilog::set_pfx('ali');

        $this->paramlist=[
            'token' => 'string',
            'out_pay_order_id' =>'string',
            'transaction_id' => 'string',
            'amount' => 'int',
            'amount_trans_in' => 'int',
        ];

        $this->check_params();
        $this->check_token();

        $order_id  = IDMan::order_id();
        $ret = (new AlimpModel())->trade_refund($this->argv['out_pay_order_id'],$this->argv['transaction_id'],$order_id,$this->argv['amount'],'用户退款');

        $this->resp['info'] = $ret;
    }
}